<?php

class Frontend_MinifyController extends Zend_Controller_Action 
{
	
	private $_minifyOptions;
	
    public function init()
    {
        /* Initialize action controller here */
    	
		$this->_helper->viewRenderer->setNoRender ();
		$this->_helper->layout->disableLayout();
		
		$bootstrap = $this->getInvokeArg('bootstrap');
		
		$options = $bootstrap->getOptions();
		
		$this->_minifyOptions = $options['resources']['view']['minify'] ;
		
    }
	
	public function scriptAction(){
		
		echo 'something works';
	}	
	
	public function styleAction(){
		
		$hash = $this->_getParam('hash');		
		$minifiedHashed = substr($hash, 0, -4);
		
		try {
			
			$cache = Zend_Registry::get('Zend_Cache');			
			$data = $cache->load( 'FrontendCssCache'.$minifiedHashed );
			
		}catch (Exception $e){
			
			throw new Exception('You must have Zend Cache configured to use this functionality', 0);
			
		}
		
        $this->getResponse()->setHeader( 'content-type', 'text/css', true );
        
        $this->getResponse()->setHeader( 'cache-control', 'private' , true);
        
        $this->getResponse()->setHeader( 'pragma', 'cache' , true);
        
        $this->getResponse()->setHeader( 'expires', strftime("%a , %d %b %Y %H:%M:%S", time() + ( 60 * 60 * 24 * 30)), true);
		
		echo $data;
		
	}
	
}